<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Qingwuit\Models\Announcements;
use App\Qingwuit\Models\Notice;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class NoticesController extends Controller
{
    protected $modelName = 'Notice';
    protected $setUser = true;
//公告
    public function notices(){
        $user_id = $this->getUserId('users');
//        print_r($user_id);die;
        $data = Notice::all();
        foreach ($data as $k=>$v){
        $is_send = DB::table('issend')->where('userid',$user_id)->where('notice',$v['id'])->first();
        if ($is_send)
            $v->is_send = 1;
        }
       return $this->success($data);
    }
    //详情
    public function noticeDetails(Request $request){
//        dd(1);
        $id = $request->id;
        $data = Notice::where('id',$id)->first();
        $user_id = $this->getUserId('users');
        $arr = [
            'userid'=>$user_id,
            'notice'=>$data->id
        ];
        DB::table('issend')->insert($arr);
//        dd($data);
        $resultArray = explode('##qingwuit##', $data->content);

        $data->content = $resultArray[0];
        return $this->success($data);
    }
    public function announcements(){
        $data = Announcements::all();

        return $this->success($data);
    }
    public function announcementsDetails(Request $request){
        $id = $request->id;
        $data = Announcements::where('id',$id)->first();

        return $this->success($data);
    }
}
